package javase2.day01;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/*
 * 时间类型转换
 *     long -- Date --- Calendar
 * 提示：时间API默认值是当前时间！ 
 * 
 * */
public class Demo2 {
	public static void main(String[] args){
		long now = System.currentTimeMillis();
		Date date = new Date();
		long l = date.getTime();
		System.out.println(now);
		System.out.println(l);
		//相当于将long转换为Date
		date.setTime(0);
		System.out.println(date.getYear()+1900);
		
		Calendar cal = new GregorianCalendar();
		System.out.println(cal.getTime().getTime());
		//cal.setTime(date); //将Date转换为Calendar
		int year = cal.get(Calendar.YEAR); //获取4位数年份
		int month =cal.get(Calendar.MONTH)+1;
		int day = cal.get(Calendar.DAY_OF_MONTH);
		System.out.println(year);
		System.out.println(month);
		System.out.println(day);
		SimpleDateFormat fmtDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(fmtDateFormat.format(cal.getTime()));
		System.out.println(date);
		System.getProperties().list(System.out);
		
		long l1 = -1000l*60*60*24;
		System.out.println(fmtDateFormat.format(l1));
		System.out.println(fmtDateFormat.format(1)); //可以直接格式long
		

	}
}
